<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>login</title>
    <link rel="stylesheet" href="../css/login.css">

    <script type="text/javascript" src="../resoures/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="../resoures/vue.js"></script>
    <script type="text/javascript" src="../resoures/axios.min.js"></script>
    <script type="text/javascript" src="../resoures/layer-master/dist/layer.js"></script>
</head>

<body>
<div id="app">
    <form id="form" method="post">
        <h1 id="loginMsg">LOGIN IN</h1>
        <p><label for="username">Username:</label><input id="username" v-model="username" name="username" type="text" autocomplete="off">
        </p>

        <p><label for="password">Password:</label><input id="password" v-model="password" name="password" type="password" @keyup.enter="login"></p>
        <div id="subDiv">
            <input type="button" @click="login" class="loginButton" value="登录">
            <input type="reset" class="button" value="注册" @click="register">&nbsp;&nbsp;&nbsp;
        </div>
    </form>
</div>

<script type="text/javascript">
    const vm = new Vue({
        el: "#app",
        data: {
            username: "",
            password: "",
            user:{}
        },
        methods: {
            register(){
                location.href ="/page/register.html";
            },
            login() {
                console.log("账号",this.username)
                console.log("密码",this.password)
                let _this = this;
                axios({
                    method: "GET",
                    url: "/userlogin",
                    params: {
                        username: this.username,
                        password: this.password
                    }
                }).then(res => {
                    console.log(res.data)
                    if (res.data.code === 1) {
                        _this.user = res.data.user;
                        //将登录信息存储 设为标识 浏览器关闭后自动清除
                        sessionStorage.setItem("Linusername", res.data.user.username);
                        // console.log(res.data.user.status)
                        sessionStorage.setItem("isAdmin", res.data.user.status);
                        // sessionStorage.setItem("token", res.data.token);
                        location.href = "/index";
                    } else {
                        location.reload();
                        alert("密码错误")
                        console.log("密码错误")
                    }
                })
            }
        }
    })
</script>

</body>
</html>